package cn.hadron.aa.action.admin;
import java.util.*;
import javax.annotation.Resource;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import cn.hadron.aa.entity.Article;
import cn.hadron.aa.entity.Channel;
import cn.hadron.aa.service.ArticleService;
import cn.hadron.aa.service.ChannelService;
import cn.hadron.aa.util.Pager;

import com.opensymphony.xwork2.ActionSupport;
@Controller
@Scope("prototype") 
@ParentPackage("admin")
@Namespace("/admin")
public class ChannelAction extends ActionSupport {
	private int id;   //页号
	private int cid;  //栏目号 
	private Channel channel;
	private List<Channel> clist=new ArrayList<>();
	private Pager<Article> pager ;
	@Resource(name="articleService")
	private ArticleService as;
	@Resource(name="channelService")
	private ChannelService cs;
	//显示栏目
	@Action(value="channel",results={@Result(name="success",location="/admin/channel.jsp")})
	public String channel() throws Exception {
		//准备Channel数据
		clist=cs.getAllChannel();
		return SUCCESS;
	}	
	//添加新栏目
	@Action(value="addChannel",
			interceptorRefs={ 
	        	@InterceptorRef("defaultStack"),  
	            @InterceptorRef("authority")  
	        },
			results={
				@Result(name="success",location="/admin/channel.jsp"),
				@Result(name="input",location="/admin/channel.jsp")})
	public String add() throws Exception {
		clist=cs.getAllChannel();
		if(channel!=null){
			cs.add(channel);
			return SUCCESS;
		}
		return INPUT;
	}
	
	public List<Channel> getClist() {
		return clist;
	}
	public void setClist(List<Channel> clist) {
		this.clist = clist;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getCid() {
		return cid;
	}
	public void setCid(int cid) {
		this.cid = cid;
	}
	public Channel getChannel() {
		return channel;
	}
	public void setChannel(Channel channel) {
		this.channel = channel;
	}
	public Pager<Article> getPager() {
		return pager;
	}
	public void setPager(Pager<Article> pager) {
		this.pager = pager;
	}
}
